-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package:new("iberia_cards", Package.CardPack)
extension.extensionName = "iberia"

Fk:loadTranslationTable{ ["iberia_cards"] = "海嗣国战",}

extension:loadSkillSkelsByPath("./packages/iberia/pkg/cards/skills")

local I = require "packages/iberia/utility"

---@param params any @ 参数：name, lists
local loadCards = function (params)
  local name = params.name
  local lists = params.lists
  if not (name and lists) then return end
  for s, l in ipairs(lists) do
    for _, n in ipairs(l) do
      extension:addCardSpec(name, s, n)
    end
  end
end

local changeColor = function(tail)
  local color = string.find(tail, "折冲") and "#CC0080" or "#1F3855"
  return "<span style='color: ".. color ..";'>"..tail.."</span>"
end

local thunder__slash = fk.CreateCard{
  name = "iberia_thunder__slash",
  type = Card.TypeBasic,
  skill = "iberia_thunder__slash_skill",
  is_damage_card = true,
}
Fk:loadTranslationTable{
  ["iberia_thunder__slash"] = "雷杀",
  [":iberia_thunder__slash"] = "基本牌<br/>"
  .."<b>时机</b>：出牌阶段<br/>"
  .."<b>目标</b>：攻击范围内的一名角色<br/>"
  .."<b>效果</b>：对目标角色造成1点雷电伤害。<br/>"
  ..changeColor("<b>折冲</b>：你使用此牌时无距离限制"),
}
extension:loadCardSkels{thunder__slash}

local fire__slash = fk.CreateCard{
  name = "iberia_fire__slash",
  type = Card.TypeBasic,
  skill = "iberia_fire__slash_skill",
  is_damage_card = true,
}
Fk:loadTranslationTable{
  ["iberia_fire__slash"] = "火杀",
  [":iberia_fire__slash"] = "基本牌<br/>"
  .."<b>时机</b>：出牌阶段<br/>"
  .."<b>目标</b>：攻击范围内的一名角色<br/>"
  .."<b>效果</b>：对目标角色造成1点火焰伤害。<br/>"
  ..changeColor("<b>折冲</b>：额外的，你弃置目标角色一张牌。"),
  ["#iberia_fire__slash_skill-discard"] = "火杀：请弃置目标角色一张牌。",
}
extension:loadCardSkels{fire__slash}

local dismantlement = fk.CreateCard{
  name = "iberia__dismantlement",
  type = Card.TypeTrick,
  skill = "iberia__dismantlement_skill",
}
Fk:loadTranslationTable{
  ["iberia__dismantlement"] = "过河拆桥",
  [":iberia__dismantlement"] = "锦囊牌<br/>"
  .."<b>时机</b>：出牌阶段<br/>"
  .."<b>目标</b>：区域内有牌的一名角色<br/>"
  .."<b>效果</b>：弃置目标角色区域内的一张牌。<br/>"
  ..changeColor("<b>帷幄</b>：结算中目标角色的手牌对你可见。"),

  ["iberia__dismantlement_skill"] = "过河拆桥",
  ["#iberia__dismantlement_skill"] = "选择一名区域内有牌的角色，弃置其区域内的一张牌",
}
extension:loadCardSkels{dismantlement}

local crafty_escape = fk.CreateCard{
  name = "iberia__crafty_escape",
  type = Card.TypeTrick,
  skill = "iberia__crafty_escape_skill",
  is_passive = true,
}
Fk:loadTranslationTable{
  ["iberia__crafty_escape"] = "金蝉脱壳",
  [":iberia__crafty_escape"] = "锦囊牌<br />"
  .."<b>时机</b>：当一张锦囊牌对你生效前<br />"
  .."<b>条件</b>：若你的手牌唯一<br />"
  .."<b>目标</b>：该锦囊牌<br />"
  .."<b>效果</b>：该牌对你无效。<br />"
  ..changeColor("<b>帷幄</b>：额外的，你摸两张牌。"),

  ["iberia__crafty_escape_skill"] = "金蝉脱壳",
  ["#iberia__crafty_escape-ask"] = "是否使用【金蝉脱壳】，令 %arg 对你无效？",
}
extension:loadCardSkels{crafty_escape}

local iron_chain = fk.CreateCard{
  name = "iberia__iron_chain",
  type = Card.TypeTrick,
  skill = "iberia__iron_chain_skill",
  special_skills = { "recast" },
  multiple_targets = true,
}
Fk:loadTranslationTable{
  ["iberia__iron_chain"] = "铁索连环",
  [":iberia__iron_chain"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：至多两名角色<br />"
  .."<b>效果</b>：目标角色横置或重置。<br />"
  ..changeColor("<b>帷幄</b>：额外的，若目标角色因此横置，你可以令其摸一张牌。<br />")
  ..changeColor("<b>折冲</b>：你可以额外指定一名角色为目标。"),
}
extension:loadCardSkels{iron_chain}

local lure_tiger = fk.CreateCard{
  name = "iberia__lure_tiger",
  type = Card.TypeTrick,
  skill = "iberia__lure_tiger_skill",
  multiple_targets = true,
}
Fk:loadTranslationTable{
  ["iberia__lure_tiger"] = "调虎离山",
  [":iberia__lure_tiger"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：至多两名其他角色<br />"
  .."<b>效果</b>："..I.href("调离").."目标角色直到回合结束。<br />"
  ..changeColor("<b>帷幄</b>：若仅指定一名角色为目标，你摸一张牌。"),
  ["#iberia__lure_tiger_skill"] = "选择至多两名其他角色，调离其直到回合结束。",
}
extension:loadCardSkels{lure_tiger}

local diversion = fk.CreateCard{
  name = "iberia__diversion",
  type = Card.TypeTrick,
  skill = "iberia__diversion_skill",
}
Fk:loadTranslationTable{
  ["iberia__diversion"] = "声东击西",
  [":iberia__diversion"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：距离为1的一名角色<br />"
  .."<b>效果</b>：你交给目标角色一张手牌并选择另一名角色，目标角色将两张牌交给该角色。<br />"
  ..changeColor("<b>帷幄→非帷幄</b>：改为该角色获得目标角色两张牌。"),

  ["iberia__diversion_skill"] = "声东击西",
  ["#iberia__diversion_skill"] = "选择距离为1的一名角色，交给其一张手牌，并选择另一名角色，目标角色将两张牌交给该角色",
  ["#iberia__diversion-give"] = "声东击西：交给 %dest 一张手牌，并选择其要将两张牌交给的目标",
  ["#iberia__diversion-give2"] = "声东击西：交给 %dest 两张牌",
}
extension:loadCardSkels{diversion}

local await_exhausted = fk.CreateCard{
  name = "iberia__await_exhausted",
  type = Card.TypeTrick,
  skill = "iberia__await_exhausted_skill",
  multiple_targets = true,
}
Fk:loadTranslationTable{
  ["iberia__await_exhausted"] = "以逸待劳",
  [":iberia__await_exhausted"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：所有同势力角色<br />"
  .."<b>效果</b>：目标角色摸两张牌，然后弃置两张牌。<br />"
  ..changeColor("<b>帷幄</b>：此牌结算完成后，你可以结束当前回合。"),
  ["#iberia__await_exhausted_skill"] = "所有同势力角色各摸两张牌，然后弃置两张牌",
}
extension:loadCardSkels{await_exhausted}

local befriend_attacking = fk.CreateCard{
  name = "iberia__befriend_attacking",
  type = Card.TypeTrick,
  skill = "iberia__befriend_attacking_skill",
}
Fk:loadTranslationTable{
  ["iberia__befriend_attacking"] = "远交近攻",
  [":iberia__befriend_attacking"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：一名异势力角色<br />"
  .."<b>效果</b>：你与目标角色各摸两张牌。<br />"
  ..changeColor("<b>帷幄</b>：你多摸一张牌，目标角色少摸一张牌。"),
  ["#iberia__befriend_attacking_skill"] = "选择一名其他角色，与其各摸两张牌",
}
extension:loadCardSkels{befriend_attacking}

local duel = fk.CreateCard{
  name = "iberia__duel",
  type = Card.TypeTrick,
  skill = "iberia__duel_skill",
  is_damage_card = true,
}
Fk:loadTranslationTable{
  ["iberia__duel"] = "决斗",
  [":iberia__duel"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：一名其他角色<br />"
  .."<b>效果</b>：目标角色与你需轮流打出【杀】，直到一方放弃打出。首先放弃打出的一方另一方造成的1点伤害。<br />"
  ..changeColor("<b>折冲→非折冲</b>：目标角色每次需多打出一张【杀】。"),
}
extension:loadCardSkels{duel}

local fire_attack = fk.CreateCard{
  name = "iberia__fire_attack",
  type = Card.TypeTrick,
  skill = "iberia__fire_attack_skill",
  is_damage_card = true,
}
Fk:loadTranslationTable{
  ["iberia__fire_attack"] = "火攻",
  [":iberia__fire_attack"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：一名有手牌的角色<br />"
  .."<b>效果</b>：目标角色须展示一张手牌，然后你可以弃置一张花色与之相同的手牌并对其造成1点火焰伤害。<br />"
  ..changeColor("<b>折冲</b>：你可以失去1点体力来代替弃牌。"),
}
extension:loadCardSkels{fire_attack}

local drowning = fk.CreateCard{
  name = "iberia__drowning",
  type = Card.TypeTrick,
  skill = "iberia__drowning_skill",
  is_damage_card = true,
}
Fk:loadTranslationTable{
  ["iberia__drowning"] = "水淹七军",
  [":iberia__drowning"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：装备区里有牌的一名其他角色<br />"
  .."<b>效果</b>：目标角色选择一项：1.弃置装备区里的所有牌；2.受到1点雷电伤害。<br />"
  ..changeColor("<b>折冲</b>：额外的，你可以获得一张因此被弃置的牌。"),
  ["iberia__drowning_throw"] = "弃置装备区里的所有牌",
  ["iberia__drowning_damage"] = "受到 %src 造成的1点雷电伤害",
  ["#iberia__drowning_skill"] = "选择一名装备区里有牌的其他角色，其选择：<br/>1.弃置装备区里的所有牌；2.受到1点雷电伤害",
}
extension:loadCardSkels{drowning}

local savage_assault = fk.CreateCard{
  name = "iberia__savage_assault",
  type = Card.TypeTrick,
  skill = "iberia__savage_assault_skill",
  is_damage_card = true,
  multiple_targets = true,
}
Fk:loadTranslationTable{
  ["iberia__savage_assault"] = "南蛮入侵",
  [":iberia__savage_assault"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>：所有其他角色<br />"
  .."<b>效果</b>：目标角色需打出一张【杀】，否则受到1点伤害。<br />"..
  changeColor("<b>折冲</b>：你可以令此牌对一名目标多结算一次。"),
  ["#iberia__savage_assault-ex"] = "南蛮入侵：可以令此牌对一名目标多结算一次",
}
extension:loadCardSkels{savage_assault}

local archery_attack = fk.CreateCard{
  name = "iberia__archery_attack",
  type = Card.TypeTrick,
  skill = "iberia__archery_attack_skill",
  is_damage_card = true,
  multiple_targets = true,
}
Fk:loadTranslationTable{
  ["iberia__archery_attack"] = "万箭齐发",
  [":iberia__archery_attack"] = "锦囊牌<br />"
  .."<b>时机</b>：出牌阶段<br />"
  .."<b>目标</b>所有其他角色<br />"
  .."<b>效果</b>：目标角色需打出一张【闪】，否则受到1点伤害。<br />"
  ..changeColor("<b>折冲</b>：你可以取消此牌一名目标。"),
  ["#iberia__archery_attack-cancel"] = "万箭齐发：你可以取消此牌一名目标",
}
extension:loadCardSkels{archery_attack}

local xbow = fk.CreateCard{
  name = "iberia_xbow",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeWeapon,
  attack_range = 1,
  equip_skill = "#iberia_xbow_skill",
}
Fk:loadTranslationTable{
  ["iberia_xbow"] = "连弩",
  [":iberia_xbow"] = "装备牌·武器<br/>"
  .."<b>攻击范围</b>：1<br/>"
  .."<b>武器技能</b>：锁定技，你于出牌阶段内使用【杀】的次数上限+3。",
  ["#iberia_xbow_skill"] = "连弩",
}
extension:loadCardSkels{xbow}

-- Basic
loadCards{ name = "slash", lists = {
  [Card.Spade] = {5, 7, 8, 8, 9, 10},
  [Card.Club] = {3, 3, 4, 5, 8, 9, 10, 11, 12},
  [Card.Heart] = {10, 12},
  [Card.Diamond] = {11, 12},
}}

loadCards{ name = "iberia_thunder__slash", lists = {
  [Card.Spade] = {6, 7, 11},
  [Card.Club] = {6, 7, 8},
  [Card.Heart] = {},
  [Card.Diamond] = {},
}}

loadCards{ name = "iberia_fire__slash", lists = {
  [Card.Spade] = {},
  [Card.Club] = {},
  [Card.Heart] = {4},
  [Card.Diamond] = {4, 5},
}}

loadCards{ name = "jink", lists = {
  [Card.Spade] = {},
  [Card.Club] = {},
  [Card.Heart] = {7, 2, 5, 11, 13},
  [Card.Diamond] = {6, 7, 8, 6, 7, 8, 9, 10, 13},
}}

loadCards{ name = "peach", lists = {
  [Card.Spade] = {},
  [Card.Club] = {},
  [Card.Heart] = {6, 7, 8, 9, 4, 10},
  [Card.Diamond] = {2, 3},
}}

loadCards{ name = "analeptic", lists = {
  [Card.Spade] = {9},
  [Card.Club] = {9},
  [Card.Heart] = {},
  [Card.Diamond] = {9},
}}

-- Trick
extension:addCardSpec("iberia__dismantlement", Card.Spade, 3)
extension:addCardSpec("iberia__dismantlement", Card.Spade, 4)
extension:addCardSpec("iberia__dismantlement", Card.Heart, 12)

extension:addCardSpec("iberia__diversion", Card.Spade, 3)
extension:addCardSpec("iberia__diversion", Card.Spade, 4)
extension:addCardSpec("iberia__diversion", Card.Spade, 10)

extension:addCardSpec("iberia__await_exhausted", Card.Heart, 11)
extension:addCardSpec("iberia__await_exhausted", Card.Diamond, 4)

extension:addCardSpec("iberia__befriend_attacking", Card.Heart, 8)
extension:addCardSpec("iberia__befriend_attacking", Card.Heart, 9)

extension:addCardSpec("iberia__crafty_escape", Card.Spade, 11)
extension:addCardSpec("iberia__crafty_escape", Card.Spade, 13)
extension:addCardSpec("iberia__crafty_escape", Card.Club, 4)
extension:addCardSpec("iberia__crafty_escape", Card.Club, 6)
extension:addCardSpec("iberia__crafty_escape", Card.Club, 13)
extension:addCardSpec("iberia__crafty_escape", Card.Diamond, 11)

extension:addCardSpec("iberia__iron_chain", Card.Spade, 12)
extension:addCardSpec("iberia__iron_chain", Card.Club, 12)
extension:addCardSpec("iberia__iron_chain", Card.Club, 13)

extension:addCardSpec("iberia__lure_tiger", Card.Heart, 2)
extension:addCardSpec("iberia__lure_tiger", Card.Diamond, 10)

extension:addCardSpec("iberia__duel", Card.Spade, 1)
extension:addCardSpec("iberia__duel", Card.Club, 1)

extension:addCardSpec("iberia__fire_attack", Card.Heart, 1)
extension:addCardSpec("iberia__fire_attack", Card.Heart, 3)

extension:addCardSpec("iberia__drowning", Card.Heart, 13)
extension:addCardSpec("iberia__drowning", Card.Club, 12)

extension:addCardSpec("iberia__savage_assault", Card.Spade, 13)
extension:addCardSpec("iberia__savage_assault", Card.Club, 7)

extension:addCardSpec("iberia__archery_attack", Card.Heart, 1)

-- Delay
extension:addCardSpec("lightning", Card.Spade, 1)
extension:addCardSpec("indulgence", Card.Heart, 6)
extension:addCardSpec("supply_shortage", Card.Club, 10)

-- Equippment
extension:addCardSpec("wooden_ox", Card.Diamond, 5)
extension:addCardSpec("jade_seal", Card.Diamond, 1)

extension:addCardSpec("iberia_xbow", Card.Diamond, 1)
extension:addCardSpec("qinggang_sword", Card.Spade, 6)
extension:addCardSpec("ice_sword", Card.Spade, 2)
extension:addCardSpec("six_swords", Card.Diamond, 2)
extension:addCardSpec("triblade", Card.Diamond, 13)
extension:addCardSpec("spear", Card.Spade, 12)
extension:addCardSpec("axe", Card.Diamond, 5)
extension:addCardSpec("sa__halberd", Card.Diamond, 12)

extension:addCardSpec("eight_diagram", Card.Spade, 2)
extension:addCardSpec("nioh_shield", Card.Club, 2)
extension:addCardSpec("silver_lion", Card.Club, 1)
extension:addCardSpec("vine", Card.Club, 2)

extension:addCardSpec("dilu", Card.Club, 5)
extension:addCardSpec("jueying", Card.Spade, 5)

extension:addCardSpec("chitu", Card.Heart, 5)
extension:addCardSpec("jingfan", Card.Heart, 3)

return extension
